Skip to main content

JOIN

caution

Join is available starting from QQL 5.7.3.

A JOIN operation allows you to combine two streams by matching messages based on one or more keys.

Our implementation of JOIN is based on an in-memory hash map:

  1. The right-hand stream is executed first and fully materialized in memory using subqueries.

  2. From this result, a hash map is built, where the key is one or more fields (simple or composite).

  3. As messages flow through the left-hand stream, each message looks up its key in the map, extracting array of objects from right-hand stream.

  4. If matches are found, they are expanded and merged with the original message using ARRAY JOIN.

  5. The result is a stream where each left-hand message is enriched with data from the right-hand side.

JOIN supports:

  • USING clause (when both streams have a field with the same name).

  • ON clause (explicit condition, useful for complex join conditions).

  • Multiple keys.

  • Variants such as LAST JOIN, LEFT JOIN.

Limitations​

  • The right-hand side must fit into memory (it is fully materialized).

  • Only hash-based equi-joins are supported (no inequality joins or range joins).

  • JOIN works best when the right-hand stream is relatively small reference data.

  • Keys must be hashable (supported types: INTEGER, VARCHAR, DATETIME, BOOLEAN, CHAR).

  • The left-hand side is always streaming, while the right-hand side is a static snapshot at the time of join.

Examples​


-- join BITFINEX stream with securities by symbol
SELECT * FROM BITFINEX
join securities using(symbol)

-- fields from right-hand stream can be referenced by stream name
SELECT entries, securities.bitfinexSymbolFeed FROM "BITFINEX"
join securities USING(symbol)

-- fields from right-hand stream can be referenced by stream alias
SELECT entries, s.bitfinexSymbolFeed FROM "BITFINEX"
join securities as s USING(symbol)

-- fields from right-hand stream can be used in filter condition
SELECT entries, s.bitfinexSymbolFeed FROM "BITFINEX"
join securities as s USING(symbol)
where s.bitfinexSymbolFeed like 'tETC%'

-- ON
SELECT entries, s.bitfinexSymbolFeed FROM "BITFINEX"
join securities as s ON s.symbol == symbol

-- Composite key
select c.currency, currency, c.listingMarket, listingMarket, this.*, c.* from channel_0_ebbo_bar_five_minutes
join channel_0_enriched as c
using (currency, listingMarket)
where c.currency in ('SEK', 'GBX')

-- WHERE condition and join with subselect
select c.currency, currency, c.listingMarket, listingMarket, this.*, c.* from channel_0_ebbo_bar_five_minutes
join (select * from channel_0_enriched where currency in ('SEK', 'GBX')) as c
ON c.currency == currency and c.listingMarket == listingMarket

-- last
select c.currency, currency, c.listingMarket, listingMarket, this.*, c.* from channel_0_ebbo_bar_five_minutes
last join (select * from channel_0_enriched where currency in ('SEK', 'GBX')) as c
using (currency, listingMarket)

-- left
select c.currency, currency, c.listingMarket, listingMarket, this.*, c.* from channel_0_ebbo_bar_five_minutes
left last join (select * from channel_0_enriched where currency in ('SEK', 'GBX')) as c
ON c.currency == currency and c.listingMarket == listingMarket

-- join + aggregate over time
select c.currency, currency, c.listingMarket, listingMarket, count{}(), avg{}(lastBidPrice), this.*, c.* from channel_0_ebbo_bar_five_minutes
join channel_0_enriched as c
ON c.currency == currency and c.listingMarket == listingMarket
over time (1s)
limit 5

-- More complex join ON condition
select * from alltypesrand as t
join alltypesrand as s
ON (s.longField % 10) == (t.byteField) and substr(s.asciiTextField, 0, 3) == substr(t.symbol, 0, 3)

LEFT JOIN​

A LEFT JOIN guarantees that all messages from the left-hand stream appear in the result, even if no match exists in the right-hand side.

If no match is found, all fields from the right-hand stream are NULL. This is useful for example, for detecting missing records.

SELECT entries, c.bitfinexSymbolFeed
FROM "BITFINEX"
LEFT JOIN securities AS c ON c.symbol == symbol

LAST JOIN​

A LAST JOIN attaches the latest matching row from the right-hand stream instead of all matches.

Under the hood, regular/LEFT JOIN build the right-hand hash map using arrayMap{} semantics (a key can hold multiple matching rows), while LAST JOIN builds it using map{} semantics (a key holds a single row, and the last one wins).

This is critical in time-series and streaming use cases, where you often only want the most recent metadata/state:

  • Attaching the latest instrument info.

  • Adding the most recent configuration or reference value.

  • Temporal enrichment in financial or sensor data.

SELECT *
FROM channel_0_ebbo_bar_five_minutes
LAST JOIN channel_0_enriched AS c
USING(currency, listingMarket)